<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div id="app">
        <com-a></com-a>
        <com-b ref="comb"></com-b>
    </div>
    <template id="coma">
      <div>
        <h1>这是A组件</h1>
        <button @click="xiug">点击修改b组件</button>
      </div>
    </template>
    <template id="comb">
      <div>
        <h1>这是B组件--{{message}}</h1>
      </div>
    </template>
    <script>
        let comA = {
            template: "#coma",
            methods: {
                xiug() {
                    console.log(this.$parent.$refs.comb);
                    this.$parent.$refs.comb.addxg();
                },
            },
        };
        let comB = {
            template: "#comb",
            data() {
                return {
                    message: "这是b组件",
                };
            },
            methods: {
                addxg() {
                    this.message = "点击修改了";
                },
            },
        };
        new Vue({
            el: "#app",
            components: {
                comA,
                comB,
            },
        });
    </script>
</body>

</html>